package com.code.leetcode.offer;

import com.code.leetcode.utils.ListNode;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/7/31 18:35
 */
public class The25 {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode root = new ListNode(0);
        ListNode head = root;
        while (l1 != null && l2 != null) {
            if (l1.val <= l2.val) {
                root.next = l1;
                l1 = l1.next;
            } else {
                root.next = l2;
                l2 = l2.next;
            }
            root = root.next;
        }
        if(l1 != null) root.next = l1;
        if(l2 != null) root.next = l2;
        return head.next;
    }
}
